// import { getCustomSelector } from "@/api/test";

//表格动态列
export async function getActiveCol(whichTable, mycustomColList, activeCol) {
  // let res = await getCustomSelector({
  //   From: whichTable,
  // });
  let res = {}
  let copyList = [];
  let copyCustomColList = [...mycustomColList];
  res.data?.map((item, index) => {
    //动态columns
    copyList.push({
      key: item.id,
      label: item.name,
      visible: true,
      thousandsSeparator: item.thousandsSeparator,
      decimalPlaces: item.decimalPlaces,
    });
    //自定义列数据
    copyCustomColList.push({
      label: item.name,
      id: item.id,
      type: item.type,
      attributes: item.attributes,
      isTextarea: item.isTextarea,
      timePrecision: String(item.timePrecision),
      thousandsSeparator: item.thousandsSeparator,
      decimalPlaces: item.decimalPlaces,
      placeholder: item.placeholder,
      prompt: item.prompt,
      radioList:
        item.customFieldSelects &&
        item.customFieldSelects.map((item) => {
          return {
            label: item.customSelect.text,
            id: item.customSelectId,
          };
        }),
    });
  });
  //去重
  let list = [];
  let obj = {};
  copyList?.map((item) => {
    if (!obj[JSON.stringify(item.key)]) {
      list.push(item);
      obj[JSON.stringify(item.key)] = true;
    }
  });
  let list2 = [];
  let obj2 = {};
  copyCustomColList &&
    copyCustomColList.map((item, index) => {
      if (!obj2[JSON.stringify(item.id)]) {
        list2.push(item);
        obj2[JSON.stringify(item.id)] = true;
      }
    });
  mycustomColList = list2;
  let mycolumns = list;
  if (activeCol?.length) mycolumns = activeCol;
  return {
    mycolumns,
    mycustomColList,
  };
}

//过滤选择框类型
function filterInputType(type) {
  switch (type) {
    case "1":
      return "blur";
    case "2":
      return "blur";
    case "3":
      return "change";
    case "4":
      return "change";
    case "5":
      return "change";
    case "6":
      return "change";
    case "7":
      return "change";
  }
}

export function formatCustom(data) {
  let reg = /^a[0-9]+/g;
  let list = [];
  Object.keys(data)?.map((item) => {
    if (String(item).match(reg)) {
      list.push({
        fieldId: String(item).replace("a", ""),
        values:
          typeof data[item] == "object"
            ? JSON.stringify(data[item])
            : data[item],
      });
    }
  });
  return list
}
